//
//  SafetyViewController.m
//  何五路
//
//  Created by _ADY on 15/7/29.
//  Copyright (c) 2015年 _ADY. All rights reserved.
//

#import "SafetyViewController.h"

@interface SafetyViewController ()

@end

@implementation SafetyViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"账户安全";
        self.view.backgroundColor = bgColor;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    
    UITableView *mTableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStyleGrouped];
    mTableView.delegate = self;
    mTableView.dataSource = self;
    mTableView.sectionHeaderHeight = 0.0;
    mTableView.sectionFooterHeight = 0.0;
    mTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:mTableView];
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];//清除多余分割线
    [mTableView setTableFooterView:v];
    
    aArray = [NSArray arrayWithObjects:@"登录密码",@"手机验证",@"支付密码",nil];
    bArray = [NSArray arrayWithObjects:@"*建议您定期更改密码以保护账户安全",@"*开启后可接收资产变动提醒，可用于找回密码",@"*使用虚拟资产验证支付密码，保障资产安全",nil];
    
}

#pragma mark -
#pragma mark Table View DataSource

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    if (section == 0)
        return 0.001;
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
        return 3;
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SafetyCell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        aTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        aTableView.showsVerticalScrollIndicator = NO;
    }
    int i = (int)[[cell.contentView subviews] count] - 1;
    for(;i >= 0 ; i--)
    {
        [[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
    }
    cell.backgroundColor = [UIColor whiteColor];
    if (indexPath.section == 0)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, 5, screenMySize.size.width-50, 30) setTitle:[aArray objectAtIndex:indexPath.row] setFont:labelSize+2]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, 35, screenMySize.size.width-50, 20) setTitle:[bArray objectAtIndex:indexPath.row] setFont:labelSize-4]];
    }
    else
    {
         cell.accessoryType = UITableViewCellAccessoryNone;
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, 5, screenMySize.size.width-50, 50) setTitle:@"安全Tips" setFont:labelSize+2]];
    }
    return cell;
}

- (void)tableView:(UITableView *)table1View didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            ChangePassWordViewController *details = [[ChangePassWordViewController alloc] init];
            details.hidesBottomBarWhenPushed = YES;
            details.title = @"修改密码";
            [self.navigationController pushViewController:details animated:YES];
        }
    }
}

-(UILabel*)setFrame:(CGRect)frame setTitle:(NSString*)title setFont:(int)font
{
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 0;
    titleLabel.font = [UIFont fontWithName:@"Arial" size:font];
    titleLabel.textColor = [UIColor blackColor];
    return titleLabel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
